package org.yxing.palpalgps;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.yxing.palpalgps.domain.UserInfo;
import org.yxing.palpalgps.image.ImageCache;
import org.yxing.palpalgps.utils.LocationTools;

import android.app.Application;

public class PalPalGPSApplication extends Application {
    private static final String TAG = PalPalGPSApplication.class.getSimpleName();
    
    /**
     * 是否开启 sandbox
     */
    public static final boolean SANDBOX = false;
    
    /**
     * sdcard 上保存数据的文件夹名称
     */
    public static final String SDCARD_DIR = "PalPalGPS";
    
    /**
     * 缓存文件夹名称
     */
    public static final String SDCARD_CACHE_DIR = "cache";
    
    /**
     * 临时头像文件名称
     */
    public static final String SDCARD_PROTRAIT_FILENAME = "portrait.jpg";
    
    private static final int CORE_POOL_SIZE = 5;
    
    
    private LocationTools mLocationTools;
    
    /**
     * a user of current user login
     */
    private UserInfo User;
    
    private ImageCache mImageCache;
    
    private ExecutorService mExecutorService;
    
    public void onCreate() {
        super.onCreate();
    }
    
    public void setLocationTools(LocationTools locationTools) {
        mLocationTools = locationTools;
    }
    
    public LocationTools getLocationTools() {
        return mLocationTools;
    }

    /**
     * get user
     * @return user
     */
    public UserInfo getUser() {
        return User;
    }

    /**
     * set user
     * @param user
     */
    public void setUser(UserInfo user) {
        User = user;
    }
    
    /**
     * get image cache
     * @return
     */
    public ImageCache getImageCache() {
    	if (mImageCache == null) {
    		mImageCache = new ImageCache();
    	}
    	return mImageCache;
    }
    
    public ExecutorService getExcutorService() {
    	if (mExecutorService == null) {
    		mExecutorService = Executors.newFixedThreadPool(CORE_POOL_SIZE);
    	}
    	
    	return mExecutorService;
    }
}